package lesson3.example8;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

@Component
public class LogAspect {

	@Pointcut("execution(* lesson3.example8.UserController.list(..))")
	public void log() {
	}
	
	@Before("log()")
	public void printBeforeAdvice() {
		System.out.println("before!");
	}
	
	@After("log()")
	public void finallyAdvice() {
		System.out.println("after!");
	}

	@Around("log()")
	public Object around(ProceedingJoinPoint point) throws Throwable {
		long start = System.currentTimeMillis();
		Object result = point.proceed();
		long time = System.currentTimeMillis() - start;
		System.out.println("调用方法的耗时：" + time +"ms");
		return result;
	}
}



